import Http from './Http'
class Api extends Http {
  constructor() {
    super()
    // console.log(this)
  }
  //获取参赛人物
  async findNewVoteArtistList(page, pageSize) {
    return this.post({
      url: '/customize/findCustomizeWorksVote',
      data: {
        customizeId: 2,
        page,
        pageSize,
      },
      after: (res) => {
        this.setImg(res.data.data.list, 'listImage')
        this.setImg(res.data.data.list, 'picture')
        return res.data.data
      },
    })
  }
  //城市公益巡演
  async selectNewsList(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 9,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg')
        return res.data.data
      },
    })
  }
  //往期回顾
  async selectNewsList8(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 11,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg')
        return res.data.data
      },
    })
  }
  //大赛报道
  async selectNewsList7(page, pageSize) {
    return this.get({
      url: '/news/selectNewsList',
      data: {
        category: 10,
        page,
        pageSize,
      },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        this.setImg(res.data.data.list, 'titleImg')
        return res.data.data
      },
    })
  }
  //委员会
  async findCommitteeAllAdmin(page, pageSize) {
    return this.post({
      url: '/committee/findCommitteeList',
      data: { customizeId: 1 },
      after: (res) => {
        // localStorage.setItem("APP_TOKEN", res.data.message);
        // this.setImg(res.data.data.list, 'titleImg')
        console.log(res.data.data)
        res.data.data.forEach((item) => {
          this.setImg(item.recordList, 'titleImage')
        })
        return res.data.data
      },
    })
  }
  //查询往届
  async findHistoryVoteArtistList(data) {
    return this.post({
      url: '/customize/findHistoryVoteArtistList',
      data,
      after: (res) => {
        this.setImg(res.data.data, 'artistPortrait')
        return res.data.data
      },
    })
  }
  //查询往届LIST
  async findHistoryVoteList(data) {
    return this.post({
      url: '/customize/findHistoryVoteList',
      data,
      after: (res) => {
        return res.data.data
      },
    })
  }
  //投票
  async votePc(data) {
    return this.post({
      url: '/works/worksVote',
      data,
      after: (res) => {
        return res.data
      },
    })
  }
  //参赛人物详情
  async selectOneArtistPeople(data) {
    return this.post({
      url: '/works/findWorksOne',
      data,
      after: (res) => {
        console.log(res.data.data, '作品详情')
        this.setImg(res.data.data, 'artistPortrait')
        let data = res.data.data
        // data._artistWorks = JSON.parse(data.artistWorks)
        let IMGURL = process.env.VUE_APP_BASR_IMG_URL
        console.log(IMGURL)
        let _artistWorks = []
        // data._artistWorks.forEach((img) => {
        //   _artistWorks.push(IMGURL + img)
        // })
        data.artistPortrait = IMGURL + data.picture
        // data._artistWorks = _artistWorks
        return data
      },
    })
  }
  //查询详情
  async selectNewsFIRST(data) {
    return this.post({
      url: '/news/selectNewsFIRST',
      data,
      after: (res) => {
        return res.data.data
      },
    })
  }
  //往届
  async findHistoryVoteList(data) {
    return this.post({
      url: '/customize/findHistoryVoteList',
      data,
      after: (res) => {
        return res.data.data
      },
    })
  }
  //查询活动详情
  async findDownloadFile(data) {
    return this.post({
      url: '/customize/findDownloadFile',
      data,
      after: (res) => {
        let IMGURL = process.env.VUE_APP_BASR_IMG_URL
        res.data.data.contestVideoUrl = IMGURL + res.data.data.contestVideoUrl
        return res.data.data
      },
    })
  }
  //查询详情
  async verification(number, licensee) {
    return this.post({
      url: '/certificate/verification',
      data: {
        number,
        licensee,
      },
      after: (res) => {
        return res.data
      },
    })
  }
  //下载文件
  async downloadFiles(fileId) {
    return this.post({
      url: '/download/file?fileId=' + fileId,
      before: (ctx) => {
        // console.log(ctx);
        window.open(ctx.url)
        return Promise.resolve()
      },
      after: (res) => {
        return
      },
    })
  }
}
export default function install(vue) {
  vue.prototype.api = new Api()
}
